package form;

import javax.swing.JProgressBar;
import log.Log;

public class ProgressBar extends JProgressBar
{	
	private static ProgressBar  INSTANCE; 
	int delay = 70;

	public static ProgressBar get()
	{
		if (INSTANCE == null)
		{
			INSTANCE = new ProgressBar();
		}
		return INSTANCE;
	}
	
	ProgressBar()
	{
		super();
		this.setMaximum(100);
		this.setMinimum(0);
		this.setStringPainted(true);
	}
	
	public void reset()
	{
		this.setValue(0);
	}
	
	public void setValueDynamic(int n)
	{
		int difference = this.getValue() - n;
		if(difference > 0)
		{
			for(int i=n;i<difference;--i)
			{
				this.setValue(i);
				try 
				{
					java.lang.Thread.sleep(delay);
				} 
				catch (InterruptedException e) 
				{					
					Log.console(e.getMessage());
					return;
				}
			}
		}
		else
		{
			difference = Math.abs(difference);
			for(int i=n;i<difference;++i)
			{
				this.setValue(i);
				try 
				{
					java.lang.Thread.sleep(delay);
				} 
				catch (InterruptedException e) 
				{					
					Log.console(e.getMessage());
					return;
				}
			}
		}
	}	
	
	public void setDelay(int n)
	{
		this.delay = n;
	}
}
